#!/usr/bin/env python
# -*- coding: utf-8 -*-

"URI Class mapping to SQL table"

from django.db import models
from labman2.data.models import Base
from labman2.data.subdata.Fact.models import Fact
from django.utils.html import format_html, escape


#==============================================================================
class URI(Fact):
    "A simple numeric data entry"


    url = models.URLField(null=True, blank=True)

    def __unicode__(self):

        return u'%s <%s>: %s :%s' % (
            self.name, self.url, self.description[:32], Base.__unicode__(self))

    def show_details(self):
        'Return a list of the fields for detailed view'

        info_dict = [(self.name,
                      format_html(u"<a href=%s>%s</a>" % (escape(self.url),
                                    escape(self.url))))]
        info_dict.extend(Fact.show_details(self))
        return info_dict
